from tfpp.plan import models

def initDb():
    """
    does not work anymore
    """
    # e-mail action
    meta_data = {}
    meta_data['to'] = "{{scenario.user}}"
    meta_data['cc'] = "{{scenario.manager}}"
    meta_data['from_email'] = "Administrator"
    meta_data['subject'] = "PriA for RR#{{scenario.release_record}}"
    meta_data['message'] = "Dear {{scenario.user}}\n Would you take care of RR#{{scenario.release_record}}?\n Thanks in advance"
    meta_action = models.MetaAction.objects.get_or_create(name="send_mail_1")[0]
    meta_action.meta_class = "tfpp.action.mail.MetaMail"
    meta_action.set_meta_data(meta_data)
    meta_action.save()
    
    # script action
    meta_data = {}
    meta_data['command'] = "echo {{scenario.user}}"
    meta_action = models.MetaAction.objects.get_or_create(name="command_1")[0]
    meta_action.meta_class = "tfpp.action.script.MetaScript"
    meta_action.set_meta_data(meta_data)
    meta_action.save()
    
    # object 1
    meta_object = models.MetaObject.objects.get_or_create(name="object_1")[0]
    meta_object.meta_class = "tfpp.object.user.MetaUser"
    meta_object.save()

def test():
    """
    from test import test
    note: does not work anymore
    """

    # various init
    initDb()
    scenario = {}
    scenario['user'] = "Developer"
    scenario['manager'] = "Boss"
    scenario['release_record'] = "12345678"

    # send mail test
    print "send_mail_1"
    print "==========="
    meta_action = models.MetaAction.objects.get(name="send_mail_1")
    mail = meta_action.instantiate(scenario)
    print mail.as_text()
    print "\n"
    
    # command test
    print "command_1"
    print "========="
    meta_action = models.MetaAction.objects.get(name="command_1")
    command = meta_action.instantiate(scenario)
    print "'%s' returns '%s'" % (command.as_text(), command.action())
    print "\n"

    # object test
    print "object_1"
    print "========"
    meta_object = models.MetaObject.objects.get(name="object_1")
    user = meta_object.instantiate(scenario)
    print user.as_text()
